//
//  LGDeviceDeliverView.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2025/2/24.
//  设备发货 -- 弹框

#import "LGDeviceDeliverView.h"
#import "LGSelectItemButton.h"
#define lineHeight  viewPix(44)

@interface LGDeviceDeliverView()<LGBottomButtonDelegate>
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *nameLabel;

/**  领取设备 */
@property (nonatomic , strong)UIButton *deviceBtn;
@property (nonatomic , strong)NSMutableArray *buttonArray;

/**  领用方式 */
@property (nonatomic , strong)UIButton *typeBtn;
@property (nonatomic , strong)UIButton *offlineBtn;
@property (nonatomic , strong)UIButton *postButton;

/**  设备编号 */
@property (nonatomic , strong)UIButton *numberTitle;
@property (nonatomic , strong)UITextField *numberTF;

/**  物流品牌 */
@property (nonatomic , strong)UIButton *brandTypeTitle;
@property (nonatomic , strong)UITextField *brandTypeTF;

/**  物流单号 */
@property (nonatomic , strong)UIButton *brandNumTitle;
@property (nonatomic , strong)UITextField *brandNumTF;

/**  出库仓库 */
@property (nonatomic , strong)UIButton *warehouseTitle;
@property (nonatomic , strong)UIView *warehouseView;
@property (nonatomic , strong)UILabel *warehouseLabel;

/**   */
@property (nonatomic , strong)UIView *adressView;
/**   */
@property (nonatomic , strong)UILabel *adressLabel;
/**   */
@property (nonatomic , strong)UIButton *duplicateBtn;
/**   */
@property (nonatomic , strong)LGBottomButtonView *bottomView;

/**   */
@property (nonatomic , assign)CGFloat totalHeight;
/**   */
@property (nonatomic , assign)CGFloat warehouseH;
/**   */
@property (nonatomic , assign)CGFloat adressHeight;
/**   */
@property (nonatomic , copy)NSString *warehouseid;
/**   */
@property (nonatomic , copy)NSString *equipmentid;


@end

@implementation LGDeviceDeliverView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    }
    return self;
}

-(void)setDeviceArray:(NSArray *)deviceArray{
    _deviceArray = deviceArray;
    if ([deviceArray isKindOfClass:[NSArray class]] && deviceArray.count>0) {
        self.deviceBtn.hidden = NO;
        NSInteger lineNum = ceil(self.deviceArray.count/2.0);
        CGFloat typeTop = (lineNum-1)*(lineHeight+viewPix(10))+viewPix(12);
        [self.typeBtn mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.deviceBtn.mas_bottom).offset(typeTop);
        }];
        /*
         make.left.equalTo(self.typeBtn.mas_right).offset(viewPix(40));
         make.width.equalTo(@((Screen_W-viewPix(164))/2.0));
         */
        CGFloat itemW = (Screen_W-viewPix(164))/2.0;
        for (NSInteger i=0; i<self.deviceArray.count; i++) {
            NSDictionary *tempDic = self.deviceArray[i];
            LGSelectItemButton *button = [LGSelectItemButton buttonWithTitle:LGNSString(tempDic[@"title"]) content:@""];
            button.frame = CGRectMake(viewPix(144)+(itemW+viewPix(8))*(i%2), viewPix(88)+(lineHeight+viewPix(10))*(i/2), itemW, lineHeight);
            button.selected = ([LGNSString(tempDic[@"id"]) isEqualToString:self.equipmentid])?YES:NO;
            [button addTarget:self action:@selector(deviceButtonSelect:) forControlEvents:UIControlEventTouchUpInside];
            [self.buttonArray addObject:button];
            [self.baseView addSubview:button];
        }
    }else{
        self.deviceBtn.hidden = YES;
        [self.typeBtn mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.deviceBtn.mas_bottom).offset(-lineHeight);
        }];
    }
}

-(void)setType:(NSString *)type{
    _type = type;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.nameLabel.text = [NSString stringWithFormat:@"%@  %@",dataDic[@"patient"][@"realname"],dataDic[@"patient"][@"mobile"]];
    //领取设备
    self.equipmentid = LGNSString(dataDic[@"equipment_id"]);
    self.deviceArray = [dataDic.allKeys containsObject:@"equipment_list"] && [dataDic[@"equipment_list"] isKindOfClass:[NSArray class]]?dataDic[@"equipment_list"]:@[];
    NSInteger lineNum = ceil(self.deviceArray.count/2.0);
    CGFloat deviceHeight = [self.type isEqualToString:@"0"]?lineNum*(lineHeight+viewPix(10))-viewPix(10):0;
    
    //出库仓库
    self.warehouseid = @"";
    NSString *warehouse = @"";
    if (dataDic[@"inventory"] && [dataDic[@"inventory"] isKindOfClass:[NSDictionary class]]) {
        self.warehouseid = LGNSString(dataDic[@"inventory"][@"id"]);
        warehouse = [LGNSString(dataDic[@"inventory"][@"title"]) isEmptyString]?@"":LGNSString(dataDic[@"inventory"][@"title"]);
    }
    
    self.warehouseLabel.text = warehouse;
    CGFloat warehouseH = [warehouse textHeightWithFont:LGFont(16) maxWidth:Screen_W-viewPix(180)]+viewPix(24);
    self.warehouseH = warehouseH>lineHeight?warehouseH:lineHeight;
    [self.warehouseView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(self.warehouseH));
    }];
    
    //收货地址
    if (dataDic[@"address"] && [dataDic[@"address"] isKindOfClass:[NSDictionary class]] && [dataDic[@"address"] allKeys].count>0) {
        NSDictionary *addressDic = dataDic[@"address"];
        NSString *adress = [NSString stringWithFormat:@"%@%@%@%@%@\n%@    %@",addressDic[@"province"],addressDic[@"city"],addressDic[@"region"],addressDic[@"sub_district"],addressDic[@"address_detail"],addressDic[@"harvest_name"],addressDic[@"harvest_mobile"]];
        self.adressLabel.text = adress;
        self.adressHeight = [adress textHeightWithFont:LGFont(16) maxWidth:Screen_W-viewPix(65)]+viewPix(65); //180 + 24
    }else{
        self.adressLabel.text = @"";
        self.adressHeight = 0;
    }
    
    [self.adressView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(self.adressHeight));
    }];
    
    
    self.totalHeight = deviceHeight+self.warehouseH+(lineHeight+viewPix(12))*2+viewPix(250);
    NSString *receiptType = LGNSString(dataDic[@"receipt_type"]);
    if ([receiptType isEqualToString:@"0"]) {
        [self selectTypeAction:self.postButton];
    }else{
        [self selectTypeAction:self.offlineBtn];
    }
    
    
//    self.baseView.frame = CGRectMake(0, Screen_H, Screen_W, self.totalHeight+viewPix(20));
//    [UIView animateWithDuration:0.3 animations:^{
//        self.baseView.frame = CGRectMake(0, Screen_H-self.totalHeight, Screen_W, self.totalHeight+viewPix(20));
//    }];
}

-(void)keyboardWillShow:(NSNotification *)notification{
    NSInteger duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] integerValue];
    CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    CGFloat height = keyboardFrame.size.height;
    height = height+viewPix(330);
    [UIView animateWithDuration:duration animations:^{
        self.baseView.frame = CGRectMake(0, Screen_H-height, Screen_W, self.baseView.bounds.size.height);
    }];
}

-(void)keyboardWillHide:(NSNotification *)notification{
    NSInteger duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] integerValue];
    [UIView animateWithDuration:duration animations:^{
        self.baseView.frame = CGRectMake(0, Screen_H-self.baseView.bounds.size.height+viewPix(20), Screen_W, self.baseView.bounds.size.height);
    } completion:^(BOOL finished) {
       
    }];
}


//领用设备选取
-(void)deviceButtonSelect:(LGSelectItemButton *)sender{
    for (NSInteger i=0; i<self.buttonArray.count; i++) {
        LGSelectItemButton *button = self.buttonArray[i];
        button.selected = (button == sender)?YES:NO;
        if (button == sender) {
            NSDictionary *tempDic = self.deviceArray[i];
            self.equipmentid = LGNSString(tempDic[@"id"]);
        }
    }
}


//选择领用方式
-(void)selectTypeAction:(UIButton *)sender{
    if (sender.selected == YES) return;
    sender.selected = YES;
    [sender addBorder:@"#5E8EF5" lineWidth:1 cornerRidus:3];
    [self endEditing:YES];
    
    CGFloat numTop = viewPix(12);
    if (sender == self.offlineBtn) {
        //线下领取
        self.totalHeight -= (lineHeight+viewPix(12))*2+self.adressHeight;
        self.postButton.selected = NO;
        self.brandTypeTitle.hidden = YES;
        self.brandTypeTF.hidden = YES;
        self.brandNumTitle.hidden = YES;
        self.brandNumTF.hidden = YES;
        self.adressView.hidden = YES;
        [self.postButton addBorder:@"#D9D9D9" lineWidth:1 cornerRidus:3];
        
    }else{
        //邮寄
        numTop = (viewPix(12)+lineHeight)*2+viewPix(12);
        self.totalHeight += (lineHeight+viewPix(12))*2+self.adressHeight;
        self.offlineBtn.selected = NO;
        self.brandTypeTitle.hidden = NO;
        self.brandTypeTF.hidden = NO;
        self.brandNumTitle.hidden = NO;
        self.brandNumTF.hidden = NO;
        self.adressView.hidden = NO;
        [self.offlineBtn addBorder:@"#D9D9D9" lineWidth:1 cornerRidus:3];
    }
    
    [UIView animateWithDuration:0.3 animations:^{
        [self.warehouseTitle mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.numberTitle.mas_bottom).offset(numTop);
        }];
        self.baseView.frame = CGRectMake(0, Screen_H-self.totalHeight, Screen_W, self.totalHeight+viewPix(20));
        
    }completion:^(BOOL finished) {
        [self layoutIfNeeded];
    }];
    
}

//复制地址
-(void)copyAdressAction{
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = self.adressLabel.text;
    [TooltipView showMessage:@"复制成功" offset:0];
}

-(void)bottomButtonTouchedWithIndex:(NSInteger)index{
    if (index == 2) {
        NSMutableDictionary *saveDic = [NSMutableDictionary dictionary];
        NSString *deviceNum = self.numberTF.text;
        NSString *brandType = self.brandTypeTF.text;
        NSString *brandNum = self.brandNumTF.text;
        if ([self.deviceArray isKindOfClass:[NSArray class]] && self.deviceArray.count>0 && [self.equipmentid isEmptyString]) {
            [TooltipView showMessage:@"请选择领用设备" offset:0];
            return;
        }
        if ([deviceNum stringByReplacingOccurrencesOfString:@" " withString:@""].length == 0) {
            [TooltipView showMessage:@"请输入设备编号" offset:0];
            return;
        }
        if (self.offlineBtn.selected == NO) {
            if ([brandType stringByReplacingOccurrencesOfString:@" " withString:@""].length == 0) {
                [TooltipView showMessage:@"请输入物流品牌" offset:0];
                return;
            }
            
            if ([brandNum stringByReplacingOccurrencesOfString:@" " withString:@""].length == 0) {
                [TooltipView showMessage:@"请输入物流编号" offset:0];
                return;
            }
            [saveDic setValue:brandType forKey:@"express"];
            [saveDic setValue:brandNum forKey:@"waybill"];
        }

        if ([self.type isEqualToString:@"0"]) {
            //服务包
            [saveDic setValue:LGNSString(self.dataDic[@"id"]) forKey:@"receipt_id"];
            [saveDic setValue:deviceNum forKey:@"equipment_sn"];
            [saveDic setValue:self.equipmentid forKey:@"equipment_id"];
            
        }else{
            //商城
            [saveDic setValue:LGNSString(self.dataDic[@"order_id"]) forKey:@"order_id"];
            [saveDic setValue:deviceNum forKey:@"goods_no"];
        }
        NSString *receiveType = (self.offlineBtn.selected == YES)?@"1":@"0";
        [saveDic setValue:receiveType forKey:@"receipt_type"];
        [saveDic setValue:self.warehouseid forKey:@"inventory_outid"];
        NSString *action = [self.type isEqualToString:@"0"]?@"/doctor/equipment.equipment/shipping":@"/doctor/equipment.equipment/orderDeliver";
        [RequestUtil withPOST:action parameters:saveDic withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
            if (code == 200) {
                NSString *notifName = [self.type isEqualToString:@"0"]?@"DeviceRefreshService":@"DeviceRefreshShope";
                [[NSNotificationCenter defaultCenter] postNotificationName:notifName object:nil];
                [UIView animateWithDuration:0.3 animations:^{
                    self.baseView.frame = CGRectMake(0, Screen_H, Screen_W, self.totalHeight+viewPix(20));
                } completion:^(BOOL finished) {
                    [self removeFromSuperview];
                }];
            }else{
                [TooltipView showMessage:message offset:0];
            }
        } error:^(NSError *error) {
            [TooltipView showMessage:@"保存失败，请重试" offset:0];
        }];
    }else{
        [UIView animateWithDuration:0.3 animations:^{
            self.baseView.frame = CGRectMake(0, Screen_H, Screen_W, self.totalHeight+viewPix(20));
        } completion:^(BOOL finished) {
            [self removeFromSuperview];
        }];
    }
    
    
}


#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    [self addSubview:self.baseView];
    [self.baseView addSubview:self.titleLabel];
    [self.baseView addSubview:self.nameLabel];
    [self.baseView addSubview:self.deviceBtn];
    [self.baseView addSubview:self.typeBtn];
    [self.baseView addSubview:self.offlineBtn];
    [self.baseView addSubview:self.postButton];
    [self.baseView addSubview:self.numberTitle];
    [self.baseView addSubview:self.numberTF];
    [self.baseView addSubview:self.brandTypeTitle];
    [self.baseView addSubview:self.brandTypeTF];
    [self.baseView addSubview:self.brandNumTitle];
    [self.baseView addSubview:self.brandNumTF];
    [self.baseView addSubview:self.warehouseTitle];
    [self.baseView addSubview:self.warehouseView];
    [self.baseView addSubview:self.warehouseLabel];
    [self.baseView addSubview:self.adressView];
    [self.baseView addSubview:self.bottomView];
    [self createAdressView];
    
    [self.deviceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel.mas_bottom).offset(viewPix(10));
        make.left.equalTo(self.baseView).offset(viewPix(24));
        make.width.equalTo(@(viewPix(80)));
        make.height.equalTo(@(lineHeight));
    }];
    
    [self.typeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.deviceBtn.mas_bottom).offset(viewPix(12));
        make.left.equalTo(self.baseView).offset(viewPix(24));
        make.width.equalTo(@(viewPix(80)));
        make.height.equalTo(@(lineHeight));
    }];
    
    [self.offlineBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.typeBtn.mas_right).offset(viewPix(40));
        make.centerY.equalTo(self.typeBtn);
        make.width.equalTo(@((Screen_W-viewPix(164))/2.0));
        make.height.equalTo(@(lineHeight));
    }];
    
    [self.postButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.offlineBtn.mas_right).offset(viewPix(8));
        make.width.height.centerY.equalTo(self.offlineBtn);
    }];
    
    [self.numberTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.typeBtn.mas_bottom).offset(viewPix(12));
        make.left.width.height.equalTo(self.typeBtn);
    }];
    [self.numberTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.numberTitle.mas_right).offset(viewPix(40));
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.centerY.equalTo(self.numberTitle);
        make.height.equalTo(@(lineHeight));
    }];
    
    [self.brandTypeTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.numberTitle.mas_bottom).offset(viewPix(12));
        make.left.width.height.equalTo(self.typeBtn);
    }];
    [self.brandTypeTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.equalTo(self.numberTF);
        make.centerY.equalTo(self.brandTypeTitle);
    }];
    
    [self.brandNumTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.brandTypeTitle.mas_bottom).offset(viewPix(12));
        make.left.width.height.equalTo(self.typeBtn);
    }];
    [self.brandNumTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.equalTo(self.numberTF);
        make.centerY.equalTo(self.brandNumTitle);
    }];
    
    [self.warehouseTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.numberTitle.mas_bottom).offset(viewPix(12));
        make.left.width.height.equalTo(self.typeBtn);
    }];
    
    [self.warehouseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.brandTypeTF);
        make.top.equalTo(self.warehouseTitle);
        make.height.equalTo(@(lineHeight));
    }];
    
    [self.warehouseLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.warehouseView).offset(viewPix(12));
        make.left.equalTo(self.warehouseView).offset(viewPix(16));
        make.right.equalTo(self.warehouseView).offset(-viewPix(12));
    }];
    
    [self.adressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.warehouseView.mas_bottom).offset(viewPix(20));
        make.left.equalTo(self.typeBtn);
        make.right.equalTo(self.brandNumTF);
    }];
    
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.baseView).offset(-viewPix(10));
        make.right.equalTo(self.baseView).offset(viewPix(10));
        make.bottom.equalTo(self.baseView);
        make.height.equalTo(@(viewPix(76)+bottomSafeBarHeight/4.0+viewPix(20)));
    }];
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc] initWithFrame:CGRectMake(0, Screen_H, Screen_W, viewPix(300))];
        _baseView.backgroundColor = [UIColor whiteColor];
        _baseView.cornerRidus = 7;
    }
    return _baseView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"设备发货" colorString:@"#000000" textFont:LGFontWeight(18, UIFontWeightSemibold) textAlignment:NSTextAlignmentCenter lines:1];
        _titleLabel.frame = CGRectMake(0, viewPix(20), Screen_W, viewPix(25));
    }
    return _titleLabel;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#282828" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _nameLabel.frame = CGRectMake(viewPix(24), viewPix(56), Screen_W-viewPix(30), viewPix(22));
    }
    return _nameLabel;
}

-(UIButton *)deviceBtn{
    if(!_deviceBtn){
        _deviceBtn = [UIButton buttonWithTitle:@" 领用设备" titleFont:LGFont(16) textColor:@"#282828" imageName:@"必选项2"];
        _deviceBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _deviceBtn.userInteractionEnabled = NO;
    }
    return _deviceBtn;
}

-(UIButton *)typeBtn{
    if(!_typeBtn){
        _typeBtn = [UIButton buttonWithTitle:@" 领用方式" titleFont:LGFont(16) textColor:@"#282828" imageName:@"必选项2"];
        _typeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _typeBtn.userInteractionEnabled = NO;
    }
    return _typeBtn;
}

-(UIButton *)offlineBtn{
    if(!_offlineBtn){
        _offlineBtn = [UIButton buttonWithTitle:@"线下领取" titleFont:LGFont(16) normalColor:@"#282828" selectColor:@"#5E8EF5"];
        _offlineBtn.cornerRidus = 3;
        [_offlineBtn setBackgroundColor:@"#FFFFFF" selectColor:@"#E5F1FF"];
        [_offlineBtn addBorder:@"#5E8EF5" lineWidth:1 cornerRidus:3];
        [_offlineBtn addTarget:self action:@selector(selectTypeAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _offlineBtn;
}

-(UIButton *)postButton{
    if(!_postButton){
        _postButton = [UIButton buttonWithTitle:@"邮寄" titleFont:LGFont(16) normalColor:@"#282828" selectColor:@"#5E8EF5"];
        _postButton.cornerRidus = 3;
        [_postButton setBackgroundColor:@"#FFFFFF" selectColor:@"#E5F1FF"];
        [_postButton addBorder:@"#D9D9D9" lineWidth:1 cornerRidus:3];
        [_postButton addTarget:self action:@selector(selectTypeAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _postButton;
}

-(UIButton *)numberTitle{
    if(!_numberTitle){
        _numberTitle = [UIButton buttonWithTitle:@" 设备编号" titleFont:LGFont(16) textColor:@"#282828" imageName:@"必选项2"];
        _numberTitle.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _numberTitle.userInteractionEnabled = NO;
    }
    return _numberTitle;
}

-(UITextField *)numberTF{
    if(!_numberTF){
        _numberTF = [[UITextField alloc]init];
        _numberTF.tintColor = [UIColor colorWithString:@"#282828"];
        _numberTF.textColor = [UIColor colorWithString:@"#282828"];
        _numberTF.textAlignment = NSTextAlignmentLeft;
        _numberTF.keyboardType = UIKeyboardTypeDefault;
        _numberTF.placeholder = @"请输入";
        _numberTF.font = LGFont(16);
        _numberTF.leftViewMode = UITextFieldViewModeAlways;
        _numberTF.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, viewPix(10), lineHeight)];
        [_numberTF addBorder:@"#D9D9D9" lineWidth:1 cornerRidus:3];
    }
    return _numberTF;
}

-(UIButton *)brandTypeTitle{
    if(!_brandTypeTitle){
        _brandTypeTitle = [UIButton buttonWithTitle:@" 物流品牌" titleFont:LGFont(16) textColor:@"#282828" imageName:@"必选项2"];
        _brandTypeTitle.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _brandTypeTitle.userInteractionEnabled = NO;
        _brandTypeTitle.hidden = YES;
    }
    return _brandTypeTitle;
}

-(UITextField *)brandTypeTF{
    if(!_brandTypeTF){
        _brandTypeTF = [[UITextField alloc]init];
        _brandTypeTF.tintColor = [UIColor colorWithString:@"#282828"];
        _brandTypeTF.textColor = [UIColor colorWithString:@"#282828"];
        _brandTypeTF.textAlignment = NSTextAlignmentLeft;
        _brandTypeTF.keyboardType = UIKeyboardTypeDefault;
        _brandTypeTF.placeholder = @"请输入";
        _brandTypeTF.font = LGFont(16);
        _brandTypeTF.leftViewMode = UITextFieldViewModeAlways;
        _brandTypeTF.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, viewPix(10), lineHeight)];
        [_brandTypeTF addBorder:@"#D9D9D9" lineWidth:1 cornerRidus:3];
        _brandTypeTF.hidden = YES;
    }
    return _brandTypeTF;
}

-(UIButton *)brandNumTitle{
    if(!_brandNumTitle){
        _brandNumTitle = [UIButton buttonWithTitle:@" 物流单号" titleFont:LGFont(16) textColor:@"#282828" imageName:@"必选项2"];
        _brandNumTitle.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _brandNumTitle.userInteractionEnabled = NO;
        _brandNumTitle.hidden = YES;
    }
    return _brandNumTitle;
}

-(UITextField *)brandNumTF{
    if(!_brandNumTF){
        _brandNumTF = [[UITextField alloc]init];
        _brandNumTF.tintColor = [UIColor colorWithString:@"#282828"];
        _brandNumTF.textColor = [UIColor colorWithString:@"#282828"];
        _brandNumTF.textAlignment = NSTextAlignmentLeft;
        _brandNumTF.keyboardType = UIKeyboardTypeDefault;
        _brandNumTF.placeholder = @"请输入";
        _brandNumTF.font = LGFont(16);
        _brandNumTF.leftViewMode = UITextFieldViewModeAlways;
        _brandNumTF.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, viewPix(10), lineHeight)];
        [_brandNumTF addBorder:@"#D9D9D9" lineWidth:1 cornerRidus:3];
        _brandNumTF.hidden = YES;
    }
    return _brandNumTF;
}

-(UIButton *)warehouseTitle{
    if(!_warehouseTitle){
        _warehouseTitle = [UIButton buttonWithTitle:@" 出库仓库" titleFont:LGFont(16) textColor:@"#282828" imageName:@"必选项2"];
        _warehouseTitle.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _warehouseTitle.userInteractionEnabled = NO;
    }
    return _warehouseTitle;
}

-(UIView *)warehouseView{
    if(!_warehouseView){
        _warehouseView = [[UIView alloc]init];
        _warehouseView.backgroundColor = [UIColor colorWithString:@"#F5F7F9"];
        [_warehouseView addBorder:@"#D9D9D9" lineWidth:1 cornerRidus:3];
    }
    return _warehouseView;
}

-(UILabel *)warehouseLabel{
    if(!_warehouseLabel){
        _warehouseLabel = [UILabel lableWithText:@"" colorString:@"#282828" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _warehouseLabel;
}

-(UIView *)adressView{
    if(!_adressView){
        _adressView = [[UIView alloc]init];
        _adressView.backgroundColor = [UIColor colorWithString:@"#F5F7F9"];
        _adressView.clipsToBounds = YES;
        _adressView.hidden = YES;
        [_adressView addBorder:@"#D9D9D9" lineWidth:1 cornerRidus:3];
    }
    return _adressView;
}

-(UILabel *)adressLabel{
    if(!_adressLabel){
        _adressLabel = [UILabel lableWithText:@"" colorString:@"#282828" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _adressLabel;
}

-(void)createAdressView{
    UILabel *titleLabel = [UILabel lableWithText:@"收货地址" colorString:@"#282828" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    titleLabel.frame = CGRectMake(viewPix(16), viewPix(17), viewPix(150), viewPix(20));
    [self.adressView addSubview:titleLabel];
    UIButton *copyButton = [UIButton buttonWithTitle:@"复制" titleFont:LGFontWeight(16, UIFontWeightMedium) textColor:@"#4C87FD" frame:CGRectMake(Screen_W-viewPix(40)-viewPix(60), viewPix(12), viewPix(60), viewPix(30))];
    [copyButton addTarget:self action:@selector(copyAdressAction) forControlEvents:UIControlEventTouchUpInside];
    [self.adressView addSubview:copyButton];
    [self.adressView addSubview:self.adressLabel];
    [self.adressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.adressView).offset(viewPix(50));
        make.left.equalTo(self.adressView).offset(viewPix(16));
        make.right.equalTo(self.adressView).offset(-viewPix(13));
    }];
}

-(LGBottomButtonView *)bottomView{
    if(!_bottomView){
        _bottomView = [[LGBottomButtonView alloc] initWithItemArray:@[@{@"title":@"取消" , @"color":@"#4C87FD" ,@"type":@"bolder"},@{@"title":@"确定" , @"color":@"#4C87FD" ,@"type":@"back"}] frame:CGRectMake(0, self.baseView.bounds.size.height-bottomSafeBarHeight/4.0-viewPix(76), Screen_W+viewPix(20), viewPix(76))];
        [_bottomView setShadoWithColor:@"#D9D9D9" offset:CGSizeMake(0, -1) opacity:0.5 radius:0];
        _bottomView.backgroundColor = [UIColor whiteColor];
        _bottomView.radius = viewPix(23);
        _bottomView.delegate = self;
    }
    return _bottomView;
}

-(NSMutableArray *)buttonArray{
    if(!_buttonArray){
        _buttonArray = [NSMutableArray array];
    }
    return _buttonArray;
}

@end
